import rclpy
from rclpy.node import Node
from gobang_interfaces.msg import Serial


class SerialPublisher(Node):
    def __init__(self):
        super().__init__('serial_publisher')
        self.publisher_ = self.create_publisher(Serial, '/serial_sub', 10)
        timer_period = 2.0
        self.timer = self.create_timer(timer_period, self.timer_callback)

    def timer_callback(self):
        msg = Serial()
        msg.command = 0xA1
        msg.data = [0x00, 0x00, 0x01, 0x00]
    
        self.publisher_.publish(msg)
        self.get_logger().info(f'Published: command={msg.command}, data={msg.data}')


def main(args=None):
    rclpy.init(args=args)
    serial_publisher = SerialPublisher()
    rclpy.spin(serial_publisher)
    rclpy.shutdown()


if __name__ == '__main__':
    main()